﻿@using Pay.Core;
@{
    ViewBag.Title = "真实信息验证";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    var bankCardInfo = ViewBag.BankCardInfo as edit_merchant_bank_card_dto;
    string imgUrl = ViewBag.ImgUrl;
}
<body class="page-verify">
    <div>
        <form id="bank_card_form" name="bank_card_form" enctype="multipart/form-data" method="post" action="@Url.Action("AddOrUpdateBankCard","MerchantBankCard")">
            <input type="hidden" id="id" name="id" value="@bankCardInfo.id" />
            <input type="hidden" id="account_name" name="account_name" value="@bankCardInfo.account_name" />
            <input type="hidden" id="account_num" name="account_num" value="@bankCardInfo.account_num" />
            <input type="hidden" id="bank_name" name="bank_name" value="@bankCardInfo.bank_name" />
            <input type="hidden" id="branch_name" name="branch_name" value="@bankCardInfo.branch_name" />
            <input type="hidden" id="hand_id_card_img" name="hand_id_card_img" value="@bankCardInfo.hand_id_card_img"/>
            <div class="box">
                <div class="example mb30 bank_card_no_img" style="@(!string.IsNullOrEmpty(bankCardInfo.hand_id_card_img) ? "display:none" :"")">
                    <span class="tit fn30"></span>
                    <img src="~/Content/css/tokenmall/img/id1.png" />
                </div>
                <div class="bank_card_has_img" style="@(!string.IsNullOrEmpty(bankCardInfo.hand_id_card_img) ? "" : "display:none")">
                    <img id="bankCardImg" width="345" height="231" class="id mb30" src="@(imgUrl + bankCardInfo.hand_id_card_img)" />
                </div>
                <p class="fn28 col-gray mb40">
                    为验证是您本人进行操作，请您手持身份证正面拍照，
                    请保持五官清晰可见不可遮挡，身份证字迹清晰可见！
                </p>
                <div class="btnBox">
                    <label for="pz">
                        <input id="pz" name="pz" type="file">
                        <a id="pz_btn" href="#" class="ui-btn-buy">@(!string.IsNullOrEmpty(bankCardInfo.hand_id_card_img) ? "重新拍照" : "拍照")</a>
                    </label>
                    <a href="javascript:submitBankCard();" class="ui-btn-white bank_card_has_img" style="@(!string.IsNullOrEmpty(bankCardInfo.hand_id_card_img) ? "" : "display:none")">完成</a>
                </div> 
            </div>
        </form>
    </div>
</body>

<script type="text/javascript">
    function submitBankCard() {
        $("#bank_card_form").ajaxSubmit(function (result) {
            if (result.result_code == 1000) {
                layer.msg(result.result_msg);
                setTimeout(function () { window.location.href = '@Url.Action("MyBankCard", "MerchantBankCard")';}, 1500);
            } else {
                layer.msg(result.result_msg);
            }
        });
    }


    //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        }
        else if (window.URL != undefined) {
            // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        }
        else if (window.webkitURL != undefined) {
            // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
    $(function () {
        $("#pz").change(function () {
            if (this.files[0].size.toFixed(1) > 2 * 1024 * 1024) {
                $(this).val('');
                var hand_id_card_img = '@bankCardInfo.hand_id_card_img';
                if (hand_id_card_img != undefined && hand_id_card_img != '') {
                    $("#bankCardImg").attr("src", '@(imgUrl + bankCardInfo.hand_id_card_img)');
                    $(".bank_card_has_img").css('display', '');
                    $(".bank_card_no_img").css('display', 'none');
                } else {
                    $("#bankCardImg").attr("src", '');
                    $(".bank_card_has_img").css('display', 'none');
                    $(".bank_card_no_img").css('display', '');
                }
                layer.msg("请选择小于2M的图片");
                return false;
            }
            var objUrl = getObjectURL(this.files[0]);
            if (objUrl) {
                $("#bankCardImg").attr("src", objUrl);
                $(".bank_card_has_img").css('display', '');
                $(".bank_card_no_img").css('display', 'none');
                $("#pz_btn").html("重新拍照");
            }
        })
    })
</script>